# This file should contain all the record creation needed to seed the database with its default values.
# The data can then be loaded with the rails db:seed command (or created alongside the database with db:setup).
#
# Examples:
#
#   movies = Movie.create([{ name: 'Star Wars' }, { name: 'Lord of the Rings' }])
#   Character.create(name: 'Luke', movie: movies.first)
CrtSizeMediumMenu.delete_all
CrtSizeMediumMenu.create!(id: 1,crt_size: '1',
	crt_size_detail: '1000x560', 
	image_width: '1000',
	image_height: '560',
	 site_set_type: '2',
	 medium_id: '1',
	 crt_type: '1',
	 format: '{"crt_size":1 ,"crt_size_detail":"1000x560","siteset_type":2,"value":{"banner_path":{"image_width":1000,"image_height":560,"number":1,"format":"*.jpeg;*.jpg;*.png","min":0,"max":90},"trademark_name":{"min":0,"max":20,"punctuation":false},"trademark_path":{"image_width":512,"image_height":512,"number":1},"creative_copywriter":{"min":0,"max":30,"punctuation":true}},"type":1}'
	 )
CrtSizeMediumMenu.create!(id: 2,crt_size: '2',
	crt_size_detail: '240x180', 
	image_width: '240',
	image_height: '180',
	 site_set_type: '2',
	 medium_id: '1',
	 crt_type: '1',
	 format: '{"crt_size":2 ,"crt_size_detail":"240x180" ,"siteset_type":2,"value":{"banner_path":{"image_width":240,"image_height":180,"number":3,"format":"*.jpeg;*.jpg;*.png","min":0,"max":30},"trademark_name":{"min":0,"max":20,"punctuation":false},"trademark_path":{"image_width":512,"image_height":512,"number":1},"creative_copywriter":{"min":0,"max":15,"punctuation":true}},"type":1}'
	 )
CrtSizeMediumMenu.create!(id: 3,crt_size: '3',
	crt_size_detail: '640x288', 
	image_width: '640',
	image_height: '288',
	 site_set_type: '2',
	 medium_id: '1',
	 crt_type: '1',
	 format: '{"crt_size":3 ,"crt_size_detail":"640×288","siteset_type":2,"value":{"banner_path":{"image_width":640,"image_height":288,"number":1,"format":"*.jpeg;*.jpg;*.png","min":0,"max":30,"punctuation":true},"trademark_name":{"min":0,"max":20,"punctuation":false},"trademark_path":{"image_width":512,"image_height":512,"number":1},"creative_copywriter":{"min":0,"max":15,"punctuation":true}},"type":1}'
	 )
CrtSizeMediumMenu.create!(id: 4,crt_size: '4',
	crt_size_detail: '640x330', 
	image_width: '640',
	image_height: '330',
	 site_set_type: '2',
	 medium_id: '1',
	 crt_type: '2',
	 format: '{"crt_size":4,"crt_size_detail":"640×330","siteset_type":2,"value":{"banner_path":{"image_width":640,"image_height":330,"number":1,"format":"*.jpeg;*.jpg;*.png","min":0,"max":30},"creative_copywriter":{"min":0,"max":13,"punctuation":true}},"type":2}'
	 )
CrtSizeMediumMenu.create!(id: 5,crt_size: '5',
	crt_size_detail: '228x150', 
	image_width: '228',
	image_height: '150',
	 site_set_type: '2',
	 medium_id: '8',
	 crt_type: '5',
	 format: '{"crt_size":5 ,"crt_size_detail":"228x150" ,"siteset_type":2,"value":{"banner_path":{"image_width":228,"image_height":150,"number":3,"format":"*.jpeg;*.jpg;*.png","min":0,"max":0},"creative_copywriter":{"min":6,"max":25,"punctuation":true},"trademark_name":{"min":0,"max":10,"punctuation":false}},"type":5}'
	 )
CrtSizeMediumMenu.create!(id: 6,crt_size: '6',
	crt_size_detail: '60x286', 
	image_width: '60',
	image_height: '286',
	 site_set_type: '2',
	 medium_id: '8',
	 crt_type: '5',
	 format: '{"crt_size":6 ,"crt_size_detail":"60x286" ,"siteset_type":2,"value":{"banner_path":{"image_width":60,"image_height":286,"number":1,"format":"*.jpeg;*.jpg;*.png","min":0,"max":0},"creative_copywriter":{"min":6,"max":25,"punctuation":true},"trademark_name":{"min":0,"max":10,"punctuation":false}},"type":5}'
	 )
CrtSizeMediumMenu.create!(id: 7,crt_size: '7',
	crt_size_detail: '800x640', 
	image_width: '800',
	image_height: '640',
	 site_set_type: '2',
	 medium_id: '9',
	 crt_type: '3',
	 format: '{"crt_size":7 ,"crt_size_detail":"800x640" ,"siteset_type":2,"value":{"banner_path":{"image_width":800,"image_height":640,"number":1,"format":"*.jpeg;*.jpg;*.png","min":0,"max":300},"creative_copywriter":{"min":0,"max":40,"rows":4,"punctuation":true},"share_path":{"image_width":120,"image_height":120,"min":0,"max":10,"number":1},"share_title":{"min":0,"max":14},"share_describe":{"min":0,"max":20}},"type":3}'
	 )
CrtSizeMediumMenu.create!(id: 8,crt_size: '8',
	crt_size_detail: '640x800', 
	image_width: '640',
	image_height: '800',
	 site_set_type: '2',
	 medium_id: '9',
	 crt_type: '3',
	 format: '{"crt_size":8 ,"crt_size_detail":"640x800" ,"siteset_type":2,"value":{"banner_path":{"image_width":640,"image_height":800,"number":1,"format":"*.jpeg;*.jpg;*.png","min":0,"max":300},"creative_copywriter":{"min":0,"max":40,"rows":4,"punctuation":true},"share_path":{"image_width":120,"image_height":120,"min":0,"max":10,"number":1},"share_title":{"min":0,"max":14},"share_describe":{"min":0,"max":20}},"type":3}'
	 )
CrtSizeMediumMenu.create!(id: 9,crt_size: '9',
	crt_size_detail: '800x800', 
	image_width: '800',
	image_height: '800',
	 site_set_type: '2',
	 medium_id: '9',
	 crt_type: '3',
	 format: '{"crt_size":9 ,"crt_size_detail":"800x800" ,"siteset_type":2,"value":{"banner_path":{"image_width":800,"image_height":800,"number":1,"format":"*.jpeg;*.jpg;*.png","min":0,"max":300},"creative_copywriter":{"min":0,"max":40,"rows":4,"punctuation":true},"share_path":{"image_width":120,"image_height":120,"min":0,"max":10,"number":1},"share_title":{"min":0,"max":14},"share_describe":{"min":0,"max":20}},"type":3}'
	 )
CrtSizeMediumMenu.create!(id: 10,crt_size: '10',
	crt_size_detail: '140x425', 
	image_width: '140',
	image_height: '425',
	 site_set_type: '1',
	 medium_id: '1',
	 crt_type: '4',
	 format: '{"crt_size":10 ,"crt_size_detail":"140x425" ,"siteset_type":1,"value":{"banner_path":{"image_width":140,"image_height":425,"number":1,"format":"*.jpeg;*.png","min":0,"max":50}},"type":4}'
	 )
CrtSizeMediumMenu.create!(id: 11,crt_size: '11',
	crt_size_detail: '200x162', 
	image_width: '200',
	image_height: '162',
	 site_set_type: '1',
	 medium_id: '1',
	 crt_type: '4',
	 format: '{"crt_size":11,"crt_size_detail":"200x162" ,"siteset_type":1,"value":{"banner_path":{"image_width":200,"image_height":162,"number":1,"format":"*.jpeg;*.png","min":0,"max":30}},"type":4}'
	 )
CrtSizeMediumMenu.create!(id: 12,crt_size: '12',
	crt_size_detail: '140x226', 
	image_width: '140',
	image_height: '226',
	 site_set_type: '1',
	 medium_id: '1',
	 crt_type: '4',
	 format: '{"crt_size":12 ,"crt_size_detail":"140x226" ,"siteset_type":1,"value":{"banner_path":{"image_width":140,"image_height":226,"number":1,"format":"*.jpg;*.png;*.gif","min":0,"max":40,"play_max_time":5}},"type":4}'
	 )
CrtSizeMediumMenu.create!(id: 13,crt_size: '13',
	crt_size_detail: '198x40', 
	image_width: '198',
	image_height: '40',
	 site_set_type: '1',
	 medium_id: '1',
	 crt_type: '4',
	 format: '{"crt_size":13 ,"crt_size_detail":"198x40" ,"siteset_type":1,"value":{"banner_path":{"image_width":198,"image_height":40,"number":1,"format":"*.jpg;*.png;*.gif","min":0,"max":30,"play_max_time":5}},"type":4}'
	 )
CrtSizeMediumMenu.create!(id: 14,crt_size: '14',
	crt_size_detail: '240x180-1', 
	image_width: '240',
	image_height: '180',
	 site_set_type: '2',
	 medium_id: '14',
	 crt_type: '2',
	 format: '{"crt_size":14,"crt_size_detail":"240x180","siteset_type":2,"value":{"banner_path":{"image_width":240,"image_height":180,"number":1,"format":"*.jpeg;*.jpg;*.png","min":0,"max":100},"creative_copywriter":{"min":0,"max":26,"punctuation":true}},"type":2}'
	 )
CrtSizeMediumMenu.create!(id: 15,crt_size: '15',
	crt_size_detail: '640x288-1', 
	image_width: '640',
	image_height: '288',
	 site_set_type: '2',
	 medium_id: '14',
	 crt_type: '2',
	 format: '{"crt_size":15,"crt_size_detail":"640x288","siteset_type":2,"value":{"banner_path":{"image_width":640,"image_height":288,"number":1,"format":"*.jpeg;*.jpg;*.png","min":0,"max":100},"creative_copywriter":{"min":0,"max":26,"punctuation":true}},"type":2}'
	 )
CrtSizeMediumMenu.create!(id: 16,crt_size: '16',
	crt_size_detail: '640x320', 
	image_width: '640',
	image_height: '320',
	 site_set_type: '2',
	 medium_id: '15',
	 crt_type: '2',
	 format: '{"crt_size":16,"crt_size_detail":"640x320","siteset_type":2,"value":{"banner_path":{"image_width":640,"image_height":320,"number":1,"format":"*.jpeg;*.jpg;*.png","min":0,"max":50},"creative_copywriter":{"min":0,"max":22,"punctuation":true}},"type":2}'
	 )
CrtSizeMediumMenu.create!(id: 17,crt_size: '17',
	crt_size_detail: '320x210', 
	image_width: '320',
	image_height: '210',
	 site_set_type: '2',
	 medium_id: '15',
	 crt_type: '2',
	 format: '{"crt_size":17,"crt_size_detail":"320x210","siteset_type":2,"value":{"banner_path":{"image_width":320,"image_height":210,"number":1,"format":"*.jpeg;*.jpg;*.png","min":0,"max":50},"creative_copywriter":{"min":0,"max":22,"punctuation":true}},"type":2}'
	 )


PROTOTYPE = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789'

def flow_id
	time = DateTime.parse(Time.now.to_s).strftime('%Y%m%d%H%M%S').to_s
	"#{time}#{rand_flow_id(10)}"
end

def rand_flow_id(length)
	str = ''
	length.times do
		rand_count = rand(PROTOTYPE.length)
		str += PROTOTYPE[rand_count]
	end
	return str
end
AccountFlow.delete_all
100.times do |n|
	AccountFlow.create(account_type:1,user_id: 1,amount: n+1,balance: n+1,trade_at: Time.zone.now,trade_year: 2017,trade_month: 2,trade_day: n+1,flow_id: flow_id)
end


##广告 计划 报表
CampaignRpt.delete_all
AdGroupRpt.delete_all
@user = User.find(1)
@ad_groups = @user.ad_groups

@ad_groups&.each do |ad_group|
	@campaign = ad_group.campaign
	@time = Time.zone.now
	10.times do |n|
		AdGroupRpt.create(user_id: 1,ad_group_id: ad_group.id, campaign_id: @campaign.id,
                            campaign_type: @campaign.campaign_type, rpt_date: @time,
    												rpt_year: @time.year, rpt_month: @time.month, rpt_day: @time.day,
                            view_num: 100+n, click_num: 10+n, cost: 10*n)
  end
end

@campaigns = @user.campaigns
@campaigns&.each do | campaign |
	@ad_group_rpts =  AdGroupRpt.where(campaign_id: campaign.id)
  view_num , click_num ,cost = 0 ,0, 0
	@ad_group_rpts&.each do |ad_group_rpt|
		view_num += ad_group_rpt.view_num
		click_num += ad_group_rpt.click_num
    cost += ad_group_rpt.cost
  end

  (1..30).each do |n|
		@time = Time.zone.now
    @time = @time-n.days
		CampaignRpt.create(user_id: 1, campaign_id: campaign.id,
											 campaign_type: campaign.campaign_type, rpt_date: @time,
											 rpt_year: @time.year, rpt_month: @time.month, rpt_day: @time.day,
											 view_num: view_num, click_num: click_num, cost: cost)
  end

end


